<!DOCTYPE html>
<html>
<head>
	<title>事件监听兼容问题</title>
</head>
<body>
<div>
	<h1>sdf</h1>
</div>
</body>
<script type="text/javascript">
	
/* 事件监听的兼容

	1. addEventListener，现代浏览器

	2. attachEvent,ie独有
*/

var h1 = document.getElementsByTagName('h1')[0];
addEvent(h1, 'click', function() {
	alert('user1');
});


function addEvent(element, type, fun) {
	if(element.addEventListener) {
		element.addEventListener(type, fun);
	} else {
		element.attachEvent('on'+type, fun);
	}
}

</script>
</html>